package com.tbit.uqbike.client.controller;

import com.tbit.uqbike.client.constant.ResponseCode;
import com.tbit.uqbike.client.exception.BaseException;
import com.tbit.uqbike.client.pojo.MpBrandConfig;
import com.tbit.uqbike.client.service.MpBrandConfigService;
import com.tbit.uqbike.client.util.Assert;
import com.tbit.uqbike.client.util.OutputUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 小程序品牌配置
 *
 * @author Leon
 * 2019年12月21日 下午2:52:53
 */
@Controller
@RequestMapping("/mpBrand")
public class MPBrandController {
    @Autowired
    private MpBrandConfigService mpBrandConfigService;


    /**
     * 获取品牌信息
     *
     * @param accountId 品牌id
     * @param response  响应
     * @ignoreParams request
     */
    @RequestMapping("/getByAccountId")
    public void getByAccountId(Integer accountId, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();

        try {
            /* 校验 */
            Assert.notNull(accountId, "-10001", "账户id不能为空");

            MpBrandConfig mpBrandConfig = mpBrandConfigService.getByAccountId(accountId);

            map.put(ResponseCode.RET, ResponseCode.SUCC);
            map.put(ResponseCode.DATA, mpBrandConfig);
        } catch (BaseException e) {
            ResponseCode.printException(map, e, request);
        }

        OutputUtil.renderText(request, response, map);
    }
}